package com.bilibili.entity;

import java.util.List;

public class Page<T> {
	private List < T > data ;//查到的数据（查）
	
	private int pageNum ;//当前页页号
	
	private int pageSize ;//页大小（一页最多装多少条数据）
	
	private int totalRows ;//总条数（查）
	
	private int totalPages ;//总页数
	
	private boolean hasPrev ;//有没有上一页
	
	private boolean hasNext ;//有没有下一页
	
	private int[] totalPageNum;//总页数数组

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getTotalPages() {
		return totalPages;
	}

	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	public boolean isHasPrev() {
		return hasPrev;
	}

	public void setHasPrev(boolean hasPrev) {
		this.hasPrev = hasPrev;
	}
	
	public boolean isHasNext() {
		return hasNext;
	}

	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
	

	public int[] getTotalPageNum() {
		return totalPageNum;
	}

	public void setTotalPageNum(int[] totalPageNum) {
		this.totalPageNum = totalPageNum;
	}

	public Page() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Page(List<T> data, int pageNum, int pageSize, int totalRows) {
		super();
		this.data = data;
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalRows = totalRows;
		if(pageNum <= 1) {
			this.hasPrev = false;
		}else {
			this.hasPrev = true;
		}
		
		if(totalRows % pageSize == 0) {
			this.totalPages = totalRows / pageSize;
		}else {
			this.totalPages = (totalRows / pageSize)+1;
		}
		
		if(pageNum >= this.totalPages) {
			this.hasNext = false;
		}else {
			this.hasNext = true;
		}
		
		if(totalPages >= 5) {
			totalPageNum = new int[5];
		}else {
			totalPageNum = new int[totalPages];
		}
		
		if(pageNum <= 3 || totalPages < 5) {
			for(int i = 0;i<totalPageNum.length;i++) {
				totalPageNum[i] = i+1;
			}
		}else if(pageNum > 3 && totalPages >= pageNum+3) {
			for(int i = 0,k = pageNum-2;i<totalPageNum.length;i++,k++) {
				totalPageNum[i] = k;
			}
		}else if(totalPages < pageNum+3) {
			for(int i = 0,k = totalPages-4;i<totalPageNum.length;i++,k++) {
				totalPageNum[i] = k;
			}
		}
	}
	
}
